import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.parser.JSONToken;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.TreeSet;

public class test {
    public static void main(String[] args) {
        int[] nums1 = {1, 2, 3, 0, 0, 0};
        int m = 3;
        int[] nums2 = {2, 5, 6};
        int n = 3;
        merge(nums1, m, nums2, n);
        System.out.println(nums1);
        for (int i : nums1) {
            System.out.println(i);
        }

    }

    public static void merge(int[] nums1, int m, int[] nums2, int n) {
        if (m == 0) {
            nums1[0] = nums2[0];
        }
        if (n != 0 && m != 0) {
            int[] re = new int[nums1.length];
            int i = 0, j = 0, r = 0;
            while (i < m || j < n) {
                if (i == m) {
                    re[r] = nums2[j++];
                } else {
                    if (nums1[i] < nums2[j]) {
                        re[r] = nums1[i++];
                    } else if (nums1[i] > nums2[j]) {
                        re[r] = nums2[j++];
                    } else {
                        re[r] = nums2[j++];
                        r++;
                        re[r] = nums1[i++];
                    }
                }
                r++;
            }
            for (int k = 0; k < nums1.length; k++) {
                nums1[k] = re[k];
            }
        }
    }
}


